package sh.wn36.vehiclemanage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sh.wn36.vehiclemanage.entity.Car;
import sh.wn36.vehiclemanage.service.AccidentRecordService;
import sh.wn36.vehiclemanage.service.CarService;
import sh.wn36.vehiclemanage.util.Result;

import java.util.List;
import java.util.Map;

/**
 *报表中心
 * @author lzp
 */
@CrossOrigin
@RestController
@Api("报表中心")
@RequestMapping("/ReportCenter")
public class ReportCenterController {
    @Autowired
    CarService carService;
    @ApiOperation("获得车辆表的id和车牌号")
    @GetMapping("/queryAllCarNo")
    public Result  queryAllCarNo(){
        QueryWrapper<Car> carQueryWrapper =new QueryWrapper<>();
        carQueryWrapper.select("id","car_no");
        List<Map<String, Object>> maps = carService.listMaps(carQueryWrapper);
        return Result.OK().data("items",maps);
    }
    @Autowired
    AccidentRecordService accidentRecordService;
    @ApiOperation("根据车牌号调用各接口的数据并返回")
    @GetMapping("/queryReportByCarId/{carId}")
    public Result  queryReportByCarId(@PathVariable Integer carId){
        List<Map<String, Object>> maps = accidentRecordService.queryReportByCarId(carId);
        if (maps.size()==0){
            return Result.OK().data("items", null);
        }
        return Result.OK().data("items", maps);
    }
}
